<?php

class fenyePage {

    private $total;
    private $Dpage; //当前页
    private $Zpage; //总页数
//    private $DDpage; //当前是哪一页
    private $keyword = '';

    public function __construct($total, $Dpage, $keyword) {
        $this->total = $total;
        $this->Dpage = $Dpage; //当前页
        $this->Zpage = $this->zongyeshu();
        $this->keyword = $keyword;
//        $this->DDpage = isset($_GET['page']) ? ($_GET['page']) : 1;
//        if ($this->DDpage > $this->Zpage) {
//            //如果传来的page大于总页数
//            echo "<script type='text/javascript'>alert('抱歉，没有相关的页数！')</script>";
//        }
    }

    function zongyeshu() {
        return ceil($this->total / 15);
    }

    function fpage() {
        $keyValue = isset($_GET['page']) ? trim($_GET['page']) : '';
        if ($keyValue > $this->Zpage) {
            $keyValue = $this->Dpage;
        }





        echo "<div class='pagerInfo'>";
        echo "<span>总记录:&nbsp{$this->total}&nbsp条</span> ";
        echo "<span>总页数:{$this->Zpage}&nbsp页</span>";
        echo "<span>第:{$this->Dpage}&nbsp页</span>";
        echo "<a href='index.php?C=Xitong&A=menuList&page=1&way=S'>首页</a>";
        if ($this->Dpage > 1) {
            $prev = $this->Dpage - 1;
        } else {
            $prev = $this->Dpage;
        }
        echo "<a href='index.php?C=Xitong&A=menuList&way=S&page={$prev}&query={$this->keyword}'>上一页</a>";




        $num = 4;
        $number = '';

        //当前页之前的一一循环出来
        for ($i = $num; $i >= 1; $i--) {
            $numpage = $this->Dpage - $i;
            if ($numpage > 0) {
                $number .="<a href='index.php?C=Xitong&way=S&A=menuList&page=$numpage'>$numpage</a>";
            }
        }


        $number .= '<strong>' . $this->Dpage . '</strong>';

        //当前页之后的一一循环出来
        for ($i = 1; $i <= $num; $i++) {
            $numpage = $this->Dpage + $i;  //i=4的时候就不会执行了
            if ($numpage <= $this->Zpage) { //小于或等于就显示出来
                $number .="<a href='index.php?C=Xitong&way=S&A=menuList&page=$numpage'>$numpage</a>";
            }
        }
        echo $number;




        if ($this->Dpage < $this->Zpage) {
            $prev = $this->Dpage + 1;
        } else {
            $prev = $this->Dpage;
        }
        echo "<a href='index.php?C=Xitong&way=S&A=menuList&page={$prev}&query={$this->keyword}'>下一页</a>";
        echo "<a href='index.php?C=Xitong&way=S&A=menuList&page={$this->Zpage}'>末页</a>";
    }

}
